import 'package:flutter/material.dart';
import 'package:hospitable_rental/utils/comme_picker/common_picker.dart';
import 'package:hospitable_rental/widgets/form_item/common_form_item.dart';

class CommonSelectFormItem extends StatelessWidget {
  final String label;
  final int? value;
  final List<String> options;
  final Function(int?)? onChanged;

  const CommonSelectFormItem({
    Key? key,
    required this.label,
    this.value,
    required this.options,
    this.onChanged,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return CommonFormItem(
      label,
      contentBuilder: (context) => Container(
        height: 50.0,
        child: GestureDetector(
          behavior: HitTestBehavior.translucent,
          onTap: () async {
            var result = await CommonPicker.showPicker(
              context: context,
              options: options,
              value: value,
            );
            if (result != value && result != null && onChanged != null) {
              onChanged!(result);
            }
          },
          child: Row(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: [
              Text(value == null ? "请选择" : options[value!]),
              Icon(
                Icons.keyboard_arrow_right,
                color: Colors.black54,
              ),
            ],
          ),
        ),
      ),
    );
  }
}
